package fussbudget;

import java.util.EnumSet;
import java.util.HashSet;

import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;

import fussbudget.SQL.SQLUtility;

public class PaymentEntitySet extends HashSet<PaymentEntity>{
	public static PaymentEntity undefinedEntity;
	
	public PaymentEntitySet() {
		super();
		setupUndefined();
	}

	public void addEntity(PaymentEntity newEntity) {
		System.out.println(newEntity.getName());
		this.add(newEntity);
	}
	
	public void setupUndefined(){
		SQLUtility.lock();
		undefinedEntity = new PaymentEntity("undefined", EnumSet.of(PaymentEntity.Type.UNDEFINED));
		SQLUtility.unlock();
		addEntity(undefinedEntity);
	}
	
	public PaymentEntity getEntityByID(int id){
		for (PaymentEntity currEntity : this) {
			if(currEntity.getId() == id){
				return currEntity;
			}
		}
		return undefinedEntity;
	}

	public DefaultComboBoxModel toComboBoxModel(PaymentEntity selection) {
		DefaultComboBoxModel model = new DefaultComboBoxModel();
		for (PaymentEntity currEntity : this) {
			System.out.println(currEntity.getName());
			model.addElement(currEntity);
		}
		model.setSelectedItem(selection);
		return model;
	}
}
